package com.ppz.controller;

import com.ppz.exception.BusinessException;
import com.ppz.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.ClosedFileSystemException;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex){
        //记录日志
//发送消息给运维
//发送邮件给开发人员,ex对象发送给开发人员
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex){
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    //设置指定异常处理方案，功能等同于控制器方法，
//    出现异常后终止原理控制器执行，并转入当前方法执行
    //Exception发送给用户，安抚用户
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        System.out.println("异常，别跑捏！");
        return new Result(666,null,"异常，别跑捏！");
    }
}
